import sys
import cPickle

neighbor_map = {}
p_user_map = {}
n_user_map = {}

f = open(sys.argv[1])
f1 = open(sys.argv[2])
#f2 = open(sys.argv[3])
#f3 = open(sys.argv[4])

for l in f:
    l = l.strip()
    print l
    p = l.split()
    uid = p[0]
    neighbors = p[1]
    neighbor_weights = neighbors.split(",")

    for neighbor_weight in neighbor_weights:
        if uid not in neighbor_map:
            neighbor_map[uid] = {}

        neighbor , weight = neighbor_weight.split(":")
        if neighbor not in neighbor_map[uid]:
            neighbor_map[uid][neighbor] = 0

        neighbor_map[uid][neighbor] += int(weight)

f.close()
    
for l in f1:
    l = l.strip()
    print l
    p = l.split()
    uid = p[0]
    neighbors = p[1]
    neighbor_weights = neighbors.split(",")

    for neighbor in neighbor_weights:
        if uid not in neighbor_map:
            neighbor_map[uid] = {}

        if neighbor not in neighbor_map[uid]:
            neighbor_map[uid][neighbor] = 0

        neighbor_map[uid][neighbor] += 1

f1.close()
'''
p_count = 0
n_count = 0

for l in f2:
    l = l.strip()
    p = l.split()
    uid = p[0]
    user_p_count = int(p[1])
    user_n_count = int(p[2])
    p_count += user_p_count
    n_count += user_n_count
    user_t_count = user_n_count + user_p_count

    if uid not in p_user_map:
        p_user_map[uid] = float(user_p_count) / float(user_t_count)
    if uid not in n_user_map:
        n_user_map[uid] = float(user_n_count) / float(user_t_count)

f2.close()

t_count = p_count + n_count
one_prob = float(p_count) / float(n_count)
minus_1_prob = float(n_count) / float(n_count)

for l in f4:
    l = l.strip()
    print l
'''

o = open("neighbor_weight.bin","wb")
cPickle.dump(neighbor_weight, o)
o.close()
